#pragma once

#include "Common.hpp"

class Cal
{
public:
    // 执行计算函数
    Response Execute(Request &req) 
    {
        Response resp(0, 0); // 初始化Response
        switch(req.GetOper())
        {
            case '+':
                resp.SetResult(req.GetX() + req.GetY());
                break;

            case '-':
                resp.SetResult(req.GetX() - req.GetY());
                break;

            case '*':
                resp.SetResult(req.GetX() * req.GetY());
                break;

            case '/':
                if(req.GetY() == 0)
                {
                    // 设置code为1, 表示除零错误
                   resp.SetCode(1);
                }
                else
                {
                    resp.SetResult(req.GetX() / req.GetY());
                }

            case '%':
                if(req.GetY() == 0)
                {
                    // 设置code为2, 表示模零错误
                   resp.SetCode(2);
                }
                else
                {
                    resp.SetResult(req.GetX() % req.GetY());
                }
                break;

            default:
                // 设置code为3, 表示未知运算符
                resp.SetCode(3);
                break;
        }
        return resp;
    }
};